<template>
  <div id="home">
    <el-header>
      <el-menu router class="el-menu-demo" mode="horizontal" @select="handleSelect">
       <img
          src="./img/logo.png"
          alt=""
          class="logoImag"
          @click="$router.push('/article-list')"
        >
        <el-menu-item class="pcNav">
              <el-input size="middle" v-model="searchContent" style="width:200px" placeholder="请搜索"></el-input>
              <el-button
              style="margin-left:5px"
              size="middle" type="primary" @click="onSubmit">查询</el-button>
        </el-menu-item>
        <el-menu-item index="/article-list" class="pcNav">首页</el-menu-item>
        <el-menu-item index="/about" class="pcNav">关于博客</el-menu-item>

        <el-submenu index="2" class="pcNav">
          <template slot="title">
            <i class="el-icon-user-solid"> </i>
          </template>
          <el-menu-item @click="$router.push('/user')">个人中心</el-menu-item>
          <el-menu-item @click="logout">退出登录</el-menu-item>
        </el-submenu>

        <el-submenu index="/article-list" class="phoneNav">
          <template slot="title">
            <i class="el-icon-s-fold"> </i>
          </template>
          <el-menu-item index="/article-list">首页</el-menu-item>
          <el-menu-item index="/about">关于博客</el-menu-item>
          <el-menu-item @click="logout">退出</el-menu-item>

        </el-submenu>
      </el-menu>
    </el-header>
    <el-container class="container">
      <el-container>
        <el-main>
          <keep-alive exclude="article-detail">
            <router-view></router-view>
          </keep-alive>
        </el-main>
        <el-aside class="asideContent" width="200px">
          <el-card class="aside-card">
            <h3 class='aside-nav'> &nbsp;&nbsp; 分类</h3>
            <el-divider></el-divider>
            <div class="aside-content">
              <el-tag class="asideTag" style="cursor:pointer" v-for="label in labels" :key="label" @click="$router.push('/article-list/' + label.label + '/')">
                {{ label.label }}</el-tag>
            </div>
          </el-card>
          <el-card class="aside-card">
            <el-scrollbar style="height:260px">
              <h3 class='aside-nav'> &nbsp;&nbsp; 最新留言</h3>
            <el-divider></el-divider>
            <div class="comment-item"
            style="cursor:pointer"
            v-for="comment in comments" :key="comment"
              @click="$router.push('/article/' + comment.articleId)">
              <div class="comment-content" v-html="comment.content"></div>
              <div class="comment-info">
                <div class="comment-name">
                   <img style="height:100%;vertical-align: bottom;" :src="comment.user.icon_url" alt="">
                  {{comment.user.username }}
                </div>
                <div class="comment-date">{{ comment.createdAt }}</div>
              </div>
            </div>
            </el-scrollbar>
          </el-card>
          <el-card class="aside-card">
            <h3 class='aside-nav'> &nbsp;&nbsp; 友情链接</h3>
            <el-divider></el-divider>
            <ul class="share-link">
              <li> <a href="https://element.eleme.cn/#/zh-CN/component/icon">饿了么组件</a>
              </li>
              <li> <a href="https://cn.vuejs.org/">vue的中文文档</a>
              </li>
              <li> <a href="https://uniapp.dcloud.io/">uniapp开发文档</a>
              </li>
              <li> <a href="https://developers.weixin.qq.com/community/homepage">小程序开发者社区</a>
              </li>
              <li> <a href="https://vant-contrib.gitee.io/vant/">vant组件文档</a>
              </li>
              <li> <a href="https://www.tjcblog.com/">谭先生的个人博客</a>
              </li>
              <li> <a href="https://v3.bootcss.com/">bootstrap</a>
              </li>
              <li> <a href="https://www.nowcoder.com/">牛客网</a>
              </li>
              <li> <a href="https://www.csdn.net/ ">csdn官方网站</a>
              </li>
            </ul>
          </el-card>
        </el-aside>
      </el-container>
    </el-container>
    <div class="footer"> </div>
  </div>
</template>
<script>
import globalBus from '../../utils/globalBus'
export default {
  data () {
    return {
      searchContent: '',
      comments: [],
      labels: []
    }
  },
  watch: {
    searchContent: {
      handler (val) {
        console.log(11)
        globalBus.$emit('searchTitle', val)
      }
    }
  },
  created () {
    this.getcomment()
    this.getlabel()
  },
  methods: {
    globalBus,
    async getcomment () {
      const res = await this.$http.get('/comment/findCommentNew')
      this.comments = res.data.result
      console.log(res)
    },
    async getlabel () {
      const res = await this.$http.get('/article/findAllLabel')
      this.labels = res.data.result
      console.log(res)
    },
    onSubmit () {
    },
    logout () {
      this.$store.dispatch('user/removeToken')
      this.$store.dispatch('user/removeUser')
      window.sessionStorage.removeItem('user')
      window.sessionStorage.removeItem('token')
      this.$message.success('退出成功')
      this.$router.push('/login')
    }
  }

}
</script>
<style lang="less">
#home{
  .el-menu.el-menu--horizontal {
    text-align: right;
}
.el-menu--horizontal>.el-submenu{
      display: inline-block;
    float: none;
}
  .el-menu--horizontal>.el-menu-item {
    display: inline-block;
    float: none;
  }
.footer {
  text-align: center;
  margin: 20px 0;
}

.comment-item {
  margin-bottom: 15px;

  .comment-content {
    margin-bottom: 10px;
  }

  .comment-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #999999;
    font-size: 12px;

    .comment-name {
      line-height: 20px;
      height: 20px;
    }

    .comment-date {}
  }
}
.comment-item:hover{
  background-color: #eee;
}

 ul.share-link {
  li {
    height: 25px;
    line-height: 25px;
  }

  li a:hover {
    color: #409eff;
  }

  a::before {
    content: "";
    display: inline-block;
    height: 5px;
    width: 5px;
    background-color: #409eff;
    border-radius: 5px;
  }
}

.logoImag {
  position: absolute;
  left: 0;
  height: 61px;
}

.el-divider {
  margin: 10px 0px;
}

.aside-nav {
  height: 20px;
  line-height: 20px;
  text-align: left;
}

.aside-nav::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 22px;

  background-color: #409eff;
}

.asideTag {
  margin: 5px;
  float: left;
}

.aside-card {
  width: 95%;
  margin: 15px 0;
  height: 300px;
}

.el-menu--horizontal>.el-menu-item {
  font-size: 20px;
}

/deep/.el-submenu__title {
  font-size: 20px !important;
}

.label {
  margin: 5px;
}

.el-header,
.el-footer {
  padding: 0;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-header {
  top: 0px;
}

.el-aside {
  color: #333;
  width: 25% !important;
}

.el-main {
  color: #333;
  text-align: start;
  line-height: 20px;
  flex: 0.9;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.container {
  width: 100%;
  margin-right: auto;
  margin-left: auto;
  box-sizing: border-box;
}

.el-menu--horizontal>.el-menu-item.is-active {
  border-bottom: 2px solid #fff;
  color: #303133;
}

@media screen and (min-width: 1280px) {
  .phoneNav {
  display: none!important;
}
  .container {
    width: 1220px;
  }
.el-menu.el-menu--horizontal {
    text-align: right;
}
.el-menu--horizontal>.el-submenu{
      display: inline-block;
    float: none;
}
  .el-menu--horizontal>.el-menu-item {
    display: inline-block;
    float: none;
  }

}

@media screen and (max-width: 890px){
  .el-main{
    padding: 2px;
    flex: 1!important;
  }
}

@media screen and (max-width: 1280px) {
  .phoneNav {
  display: none!important;
}
  .container {
    width: 930px;

    /deep/.read-num {
      display: none;
    }

    /deep/.date {
      display: none;
    }
  }
}

@media screen and (max-width: 991px) {
  .asideContent{
    display: none;
  }
      .phoneNav {
      display: inline-block!important;
    }
    .pcNav {
      display: none!important;
    }
  .container {
    width: 740px;

    .el-menu-demo {
      text-align: right !important;

    }
    .el-aside,

    .el-main {
      margin: 0 auto;
    }
  }
}

@media screen and (max-width: 740px) {
  .el-container {
    width: 100%;

    .el-main {
      width: 100%;
    }
  }
}
}
 .el-scrollbar__wrap {
    overflow-x: hidden;
  }
</style>
